<?php

namespace addons\hlapp\controller;

use addons\hlapp\dto\Result;
use addons\hlapp\model\HlappProjectType;
use addons\hlapp\service\TypeStageService;
use think\Db;

class Type extends Common
{
    public $adminLogin = true;//注意：因为这是后台业务菜单所以需要管理员登录操作的
    public $pageSize = 10;
    private $typeStageService;

    public function pagelist(){
        $list = $this->typeStageService->getProjectTypes();
        $this->assign('list',$list);
        $this->fetch();
    }

    public function __construct()
    {
        parent::__construct();
        $this->typeStageService=new TypeStageService();
    }


    /**
     * 添加人员页面
     */
    public function addpage()
    {
        return $this->fetch();
    }

    /*
     * 修改页面
     */
    public function updatePage()
    {
        $id = $_GET['id'];
        $t = new  HlappProjectType();
        $type= $t->where('id', $id)->find();
        $this->assign('type', $type);
        return $this->fetch();
    }


    /**
     * 添加
     */
    public function add()
    {
        $m = new HlappProjectType();
        $type=$m->where('name', $_POST['name'])->find();
        if($type && !empty($type)){
            $r = Result::getError("已存在");
        }else{
            $id = $m->saveOrUpdata($_POST);
            $r = Result::getOk($id);
        }
        return $r;
    }

    //更新
    public function update()
    {
        $id = (new HlappProjectType())->saveOrUpdata($_POST);
        $r = Result::getOk($id);
        return $r;
    }

    // 删除
    public function delete()
    {
        $id = $_POST['id'];
        $r = HlappProjectType::get($id)->delete();
        if ($r) {
            return Result::getOk();
        } else {
            return Result::getError();
        }
    }

}